package com.group.elmboot.util;

import com.group.elmboot.mapper.OrdersMapper;
import com.group.elmboot.mapper.TransitionMapper;
import org.springframework.beans.factory.annotation.Value;

import java.math.BigDecimal;

public class CreditUtil {

    public static int getCreditByChannelIdByEventId(boolean isEarn,int channelId,int eventId,OrdersMapper ordersMapper,TransitionMapper transitionMapper,String[] creditEarnRate,String[] creditConsumeRate) throws Exception {
        BigDecimal amount;
        int credit;
        switch (channelId){
            //支付订单
            case 0:
                amount= BigDecimal.valueOf(ordersMapper.getOrdersById(eventId).getOrderTotal());
                break;
            //开通会员
            case 1:
                amount= transitionMapper.selectById(eventId).getTransition_amount();
                break;
            //兑换红包
            case 2:
                amount= BigDecimal.valueOf(eventId);
                break;
            default:
                throw new Exception("InvalidChannelId!");
        }
        if (isEarn) {
            credit=amount.multiply(new BigDecimal(creditEarnRate[channelId])).intValue();
        }
        else {
            credit=amount.multiply(new BigDecimal(creditConsumeRate[channelId])).intValue();
        }
        return credit;
    }
}
